package com.bto.solar.work.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bto.solar.work.common.BizException;
import com.bto.solar.work.constant.BizCode;
import com.bto.solar.work.entity.Area;
import com.bto.solar.work.entity.LeaseLessor;
import com.bto.solar.work.mapper.AreaMapper;
import com.bto.solar.work.mapper.LeaseLessorMapper;
import com.bto.solar.work.dao.ILeaseLessorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 承租人 服务实现类
 * </p>
 *
 * @author adrian
 * @since 2023-08-09
 */
@Service
public class LeaseLessorServiceImpl extends ServiceImpl<LeaseLessorMapper, LeaseLessor> implements ILeaseLessorService {
//
//    @Autowired
//    private LeaseLessorMapper leaseLessorMapper;
//
//    @Autowired
//    private AreaMapper areaMapper;
//
//    @Override
//    public List<LeaseLessor> getLeaseLessorList() {
//        LambdaQueryWrapper<LeaseLessor> leaseLessorLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        leaseLessorLambdaQueryWrapper.orderByDesc(LeaseLessor::getId);
//        List<LeaseLessor> leaseLessors = leaseLessorMapper.selectList(leaseLessorLambdaQueryWrapper);
//        leaseLessors.stream().forEach(LeaseLessor -> {
//            LambdaQueryWrapper<Area> wrapper = new LambdaQueryWrapper<>();
//            wrapper.eq(Area::getId , LeaseLessor.getAreaId());
////            LeaseLessor.setArea(areaMapper.selectOne(wrapper));
//        });
//        return leaseLessors;
//    }
//
//    @Override
//    public Integer addLeaseLessor(LeaseLessor leaseLessor) {
//        LambdaQueryWrapper<LeaseLessor> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(LeaseLessor::getCode , leaseLessor.getCode());
//        LeaseLessor leaseLessorOne = leaseLessorMapper.selectOne(wrapper);
//        if (leaseLessorOne != null){
//            throw new BizException(BizCode.LEASE_REDO_ERROR);
//        }
//        Date date = new Date(System.currentTimeMillis());
//        long time = date.getTime();
//        leaseLessor.setUpdatedAt(new Timestamp(time));
//        leaseLessor.setCreatedAt(new Timestamp(time));
//        Integer insert = leaseLessorMapper.insert(leaseLessor);
//        return insert;
//    }
//
//    @Override
//    public Integer updateLeaseLessor(LeaseLessor leaseLessor, Integer id) {
//        LambdaQueryWrapper<LeaseLessor> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(LeaseLessor::getId , id);
//        LeaseLessor leaseLessorOne = leaseLessorMapper.selectOne(wrapper);
//        if (leaseLessorOne == null){
//            throw new BizException(BizCode.LEASE_ABSENT_ERROR);
//        }
//        Date date = new Date(System.currentTimeMillis());
//        long time = date.getTime();
//        leaseLessor.setUpdatedAt(new Timestamp(time));
//        Integer update = leaseLessorMapper.update(leaseLessor , wrapper);
//        return update;
//    }
//
//    @Override
//    public Integer deleteLeaseLessor(Integer id) {
//        LambdaQueryWrapper<LeaseLessor> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(LeaseLessor::getId , id );
//        if (leaseLessorMapper.selectOne(wrapper) == null){
//            throw new BizException(BizCode.LEASE_ABSENT_ERROR);
//        }
//        Integer delete = leaseLessorMapper.delete(wrapper);
//        return delete;
//    }
}
